/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package stock;

import misc.JsonEncodable;
import net.sourceforge.javajson.JsonObject;

/**
 * 
 * @author Fredrik
 */
public class Sale implements JsonEncodable, Comparable<Sale> {

    private final long time;
    private String name;
    private final double price;
    private long amount;

    public Sale(long time, String name, double price, long amount) {
        this.time = time;
        this.name = name;
        this.price = price;
        this.amount = amount;
    }

    public long getTime() {
        return time;
    }

    public String getName() {
        return name;
    }

    public double getPrice() {
        return price;
    }

    public long getAmount() {
        return amount;
    }

    public void setName(String name) {
        this.name = name;
    }

    public void addAmount(long amount) {
        this.amount += amount;
    }

    @Override
    public String toString() {
        return "name=" + name + "&time=" + time + "&price=" + price
                + "&amount=" + amount;
    }

    @Override
    public void putJSON(JsonObject obj) {
        obj.put("time", time);
        obj.put("name", name);
        obj.put("price", price);
        obj.put("amount", amount);
    }

    @Override
    public boolean equals(Object other) {
        return ((Sale) other).time == time;
        // return ((Sale) other).name.equals(name);
    }

    @Override
    public int compareTo(Sale t2) {
        return Long.compare(time, t2.getTime());
    }
}
